const config = require("../config");

sockets = {
  io: null,
  createSockerServer: (server, httpServer) => {
    process.setMaxListeners(0)
    sockets.io = new server(httpServer, {
      cors: {
        origin: config.origins,
        credentials: true,
      }
    });
  },
  connect: () => {
    sockets.io.on("connection", (socket) => {
      console.log("服务端链接成功",socket.id);

      socket.on("private message",(data)=>{
          console.log("收到",data.channel)
          socket.broadcast.emit(data.channel,{msg:data.msg,fromUser:data.fromUser});
      });
      
    });
  }
};

module.exports = sockets;
